<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2019-03-14
 * Time: 15:28
 */

namespace app\common\controller;

use app\common\cachemodel\AppConfig;

include EXTEND_PATH . "aliyun-openapi-php-sdk/aliyun-php-sdk-core/Config.php";

class Aliyun
{
    private static $vod_instance;

    /**
     * 获取一个VodClient实例
     */
    public static function getVodInstance()
    {
        if (!(self::$vod_instance instanceof \DefaultAcsClient))
        {
            try
            {
                include EXTEND_PATH . 'aliyun-openapi-php-sdk/aliyun-php-sdk-core/Profile/DefaultProfile.php';
                include EXTEND_PATH . 'aliyun-openapi-php-sdk/aliyun-php-sdk-core/DefaultAcsClient.php';
                $vod = (new AppConfig())->configInfo('vod');
                $profile = \DefaultProfile::getProfile($vod['region'], $vod['access_id'], $vod['access_key']);
                self::$vod_instance = new \DefaultAcsClient($profile);
            }
            catch (\Exception $e)
            {
                printf(__FUNCTION__ . "creating VodClient instance: FAILED\n");
                printf($e->getMessage() . "\n");
                return null;
            }
        }
        return self::$vod_instance;
    }
}
